package cc.service.impl;

import cc.dao.BookDao;
import cc.dao.impl.BookDaoImpl;
import cc.entity.Book;
import cc.entity.Page;
import cc.service.BookService;

import java.util.List;

/**
 * @ClassName: BookServiceImpl
 * @Description:
 * @Author: 晓东√
 * @Date: 2024-09-04 09:36
 * @Version: 1.0
 **/
public class BookServiceImpl implements BookService {

    BookDao bookDao = new BookDaoImpl();

    @Override
    public Page<Book> selectAll(String bookName, String author, int pageNum) {

        Page<Book> page = new Page<>();

        int count = bookDao.bookSize(bookName, author);

        page.setTotalCount(count);

        page.setPageNum(pageNum);

        List<Book> books = bookDao.selectAll(bookName, author, page.getPageNum(), page.getCount());

        page.setDataList(books);

        return page;
    }

    @Override
    public boolean saveBook(Book book) {
        int count = bookDao.add(book);
        /*if (count>0){
            return true;
        }
        return false;*/

        return count > 0 ? true : false;
    }

    @Override
    public Book detail(Integer id) {
        return bookDao.selectById(id);
    }

    @Override
    public boolean updateBook(Book book) {
        int count = bookDao.updateBook(book);

        return count > 0 ? true : false;
    }
}
